package ui.swing.tabbedpane;

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import ui.swing.Console;

public class TabbedPanel extends JApplet {

	private String[] flavors = { "Chocolate", "Strawberry",
			"Vanilla Fudge Swirl", "Mint Chip", "Moncha Almond Fudge",
			"Rum Raisin", "Praline Cream", "Mud Pie" };

	private JTabbedPane tabs = new JTabbedPane();
	private JTextField txt = new JTextField();

	public void init() {
		for (int i = 0; i < flavors.length; i++) {
			tabs.addTab(flavors[i], new JButton("Tabbed pane" + i));
		}
		tabs.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				txt.setText("Tab selected: " + tabs.getSelectedIndex());
			}
		});
		Container cp = getContentPane();

		txt.setEnabled(false);
		cp.add(BorderLayout.SOUTH, txt);
		cp.add(tabs);
	}

	public static void main(String[] args) {
		Console.run(new TabbedPanel(), 350, 200);
	}
}
